<template>
  <component :is="lazyComponent" v-if="lazyComponent" />
</template>

<script setup>
import { ref, onMounted, onUnmounted, defineAsyncComponent } from "vue";
import EventBus from "@/utils/eventBus.js";
import { useStore } from "@/store/index";
const lazyComponent = ref(null);
const store = useStore();
const loadComponent = async (url) => {
  // 使用 defineAsyncComponent 和 import() 函数懒加载组件
  let LazyComponent = null;
  //  if(store.isPc==2){
  //    LazyComponent = defineAsyncComponent(() => import('./mobile.vue'));
  //  }else{
  LazyComponent = defineAsyncComponent(() => import("./pc.vue"));
  //  }
  lazyComponent.value = LazyComponent;
};
watch(() => store.isPc, (newVal) => {
  loadComponent()
}, {immediate: true})
onMounted(() => {
  if (process.client) {
    const element = document.getElementById("app");
    element.scrollTop = 0;
  }
});
</script>

<style lang="scss" scoped></style>
